package scala.demo
import scala.collection.immutable.HashMap
import scala.collection.mutable
import scala.io.StdIn
object Game {

  def main(args: Array[String]): Unit = {

    object User {

      var name: String = _
      var score: Int = _

      def showFist(name:String,score:Int):Unit={
        this.name="玩家"
        this.score+=score
        println(this.name+"得分"+this.score)
      }

    }

    object Computer {
      var name:String=_
      var score:Int=_

      def showFist(name:String,score:Int):Unit={
        this.name="电脑"
        this.score+=score
        println(this.name+"得分"+this.score)
      }
    }


    val emptyMap = new mutable.HashMap[String,Int]()

    println("------------------------------欢迎来到游戏世界--------------------------------------- ")
    println("************************************************************************************ ")
    println("**********************************猜拳开始******************************************* ")
    println("************************************************************************************ ")
    println("                     ")
    println("                     ")
    println("                     ")
    println("                     ")
    println("                     ")
    println("          请输入你的对战角色:(1.刘备;2.关羽;3.张飞。)           ")
    val str = StdIn.readLine()

    val y = str match {
      case "1" => "刘备"
      case "2" => "关羽"
      case "3" => "张飞"
    }
    println("您选择了与 " + y +"对战")
    User.name=y
    println("要开始吗？ y/n " )

    var role = HashMap("1" -> "刘备", "2" -> "关羽", "3" -> "张飞")

    var computer = HashMap("win" -> 0, "lose" -> 0, "dogfall" -> 0)
    var user = HashMap("win" -> 0, "lose" -> 0, "dogfall" -> 0)
    var flag=true

    if(!flag){


    }

    while(flag){
      var str1 = StdIn.readLine()
      if("n".equals(str1)){
        flag=false
        println(User.showFist("",user.get("win").get*2))
        println(user)
        println(Computer.showFist("",computer.get("win").get*2))
        println(computer)
        println("游戏结束！！！ " )
      }else if ("y".equals(str1)){
        println("请出拳！！！ 1.剪刀 2.石头 3.布" )

         str1 = StdIn.readLine()
        var result=str1.toInt-scala.util.Random.nextInt(3)
        if(result==1){
          println("恭喜你！！！获胜了" )
          var int = user.get("win").get.toInt + 1
         user+=("win"->int)

          int = computer.get("lose").get.toInt+1
          computer+=("lose"->int)
          println("要继续吗？ y/n " )

        }else if(result==0){
          println("平局了" )
          var int = user.get("dogfall").get.toInt + 1
          user+=("dogfall"->int)
          int = computer.get("dogfall").get.toInt+1
          computer+=("dogfall"->int)
          println("要继续吗？ y/n " )
        }else{
          println("很可惜，你输了" )
          var int = user.get("lose").get.toInt + 1
          user+=("lose"->int)
          int = computer.get("win").get.toInt+1
          computer+=("win"->int)
          println("要继续吗？ y/n " )

        }

      }else{
        flag=false
        printf("输入不规范，游戏结束")
      }
    }
  }

}
